import { S, U, getRequestId, mapField } from '../../lib/backend'
import Q from 'q'
import axios from 'axios'
import env from '../../config/common'

export default {
  getTeamRules ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/maxnums'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/maxnums'
    return axios.get(URL + '?' + U(info))
  },
  getDistributeSetting ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/maxnum/' + info.team_id
    return axios.get(URL + '?' + U(info))
  },
  saveDistributeSetting ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/maxnum/' + info.team_id
    return axios.post(URL, S(info))
  },
  getDistributeRatio ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/ratio'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/ratio'
    return axios.get(URL + '?' + U(info))
  },
  saveDistributeRatio ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/ratio'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/ratio'
    return axios.post(URL, S(info))
  },
  getTurnTeamSetting ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/sites/' + rootState.auth.site_id + '/turn_team'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/ratio'
    return axios.get(URL + '?' + U(info))
  },
  saveTurnTeamSetting ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/sites/' + rootState.auth.site_id + '/turn_team'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/ratio'
    return axios.post(URL, mapField(info, {
      'waiter_proportion': 'waiter_proportion',
      'deal_proportion': 'deal_proportion',
      'turn_team_month': 'turn_team_month'
    }))
  },
  updateInitRatio ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/update/init_count'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/POST/admin/%7Btoken%7D/distribute/ratios'
    return axios.post(URL, info)
  },
  saveRecover ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/recover'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/POST/admin/%7Btoken%7D/distribute/recover'
    return axios.post(URL, S(info))
  },
  getRecover ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/distribute_rule'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/distribute_rule'
    return axios.get(URL + '?' + U(info))
  },
  saveBonusPenaltySetting ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/award'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/POST/admin/{token}/distribute/award'
    return axios.post(URL, S(info))
  },
  saveCustomSeaDistributeRule ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/high_seas'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/POST/admin/{token}/distribute/high_seas'
    return axios.post(URL, S(info))
  },
  getCustomSeaCustom ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/high_seas'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/high_seas'
    return axios.get(URL + '?' + U(info))
  },
  getBonusPenaltySetting ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/distribute/distribute_rule'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/distribute/distribute_rule'
    return axios.get(URL, S(info))
  }

}
